import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:honeypotflutter/public/public_uuid.dart';
import 'package:honeypotflutter/publicBussine/bussine_colors.dart';
import 'package:honeypotflutter/publicBussine/bussine_font.dart';
import 'package:honeypotflutter/publicBussine/bussine_image.dart';
import 'logic.dart';

class HireRentRentBoxOnePage extends StatefulWidget {
  final String title;
  final int? count;
  final double? price;
  final Function(int count)? selectAction;
  const HireRentRentBoxOnePage({
    Key? key,
    required this.title,
    this.count,
    this.price,
    this.selectAction,
  }) : super(key: key);

  @override
  State<HireRentRentBoxOnePage> createState() => _HireRentRentBoxOnePageState();
}

class _HireRentRentBoxOnePageState extends State<HireRentRentBoxOnePage> {
  final HireRentRentBoxOneLogic logic = Get.put(HireRentRentBoxOneLogic(), tag: HLUUid.v4());

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    logic.initSetMacCount(widget.count);
    logic.selectAction = widget.selectAction;
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Row(
        children: [
          Text(widget.title ?? "",
              style: TextStyle(
                color: MGColors.text1Color,
                fontWeight: FontWeight.bold,
                fontSize: MGFont.textFont1,
              )),
          Text((widget.count ?? 0).toString(),
              style: TextStyle(
                color: MGColors.text2Color,
                fontWeight: FontWeight.bold,
                fontSize: MGFont.textFont1,
              )),
          Text("¥ ${(widget.price ?? 0).toStringAsFixed(2)}",
              style: TextStyle(
                color: MGColors.themeColor,
                fontSize: MGFont.textFont1,
              )),
          Row(
            children: [
              IconButton(
                  onPressed: () {
                    logic.subtractionBox();
                  },
                  icon: Obx(() => ColorFiltered(
                      colorFilter: ColorFilter.mode(
                        Colors.white.withOpacity(logic.subtractionEnable.value ? 0 : 0.6),
                        BlendMode.srcATop,
                      ),
                      child: Image.asset(
                        MGImage.image("hire_subtraction", type: ImagePathType.hire),
                        width: 20,
                      )))),
              Obx(() => Container(
                    child: Text(
                      logic.selectCount.toString(),
                      textAlign: TextAlign.center,
                    ),
                    width: 20,
                  )),
              IconButton(
                  onPressed: () {
                    logic.addBox();
                  },
                  icon: Obx(() => ColorFiltered(
                      colorFilter: ColorFilter.mode(
                        Colors.white.withOpacity(logic.addEnable.value ? 0 : 0.6),
                        BlendMode.srcATop,
                      ),
                      child: Image.asset(
                        MGImage.image("hire_add", type: ImagePathType.hire),
                        width: 20,
                      )))),
            ],
          )
        ],
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
      ),
    );
  }

  @override
  void dispose() {
    Get.delete<HireRentRentBoxOneLogic>();
    super.dispose();
  }
}
